package pe.gob.osinergmin.dao.impl;

import android.content.Context;

import java.util.List;

import pe.gob.osinergmin.bean.SupervisionMovilDetalleSCOP;
import pe.gob.osinergmin.dao.SupervisionMovilDetalleScopDAO;
import pe.gob.osinergmin.utils.PuntoControlUtils;

public class SupervisionMovilDetalleScopDAOImpl implements SupervisionMovilDetalleScopDAO {

    private static List<SupervisionMovilDetalleSCOP> memoryList;

    private static SupervisionMovilDetalleScopDAOImpl instance;

    @Override
    public List<SupervisionMovilDetalleSCOP> getSupervisionMovilDetalleSCOPList(Context context) throws Exception {
        if(memoryList == null){
            String json = PuntoControlUtils.readExternalFile(context, SupervisionMovilDetalleSCOP.class.getSimpleName());
            memoryList = (List<SupervisionMovilDetalleSCOP>) PuntoControlUtils.convertFromJsonStringToList(json);
        }
        return memoryList;
    }

    @Override
    public void saveSupervisionMovilDetalleSCOPListToLocal(Context context, List<SupervisionMovilDetalleSCOP> supervisionMovilDetalleSCOPList) throws Exception {
        String json = PuntoControlUtils.convertFromListToJsonString(supervisionMovilDetalleSCOPList);
        PuntoControlUtils.writeExternalFile(context, SupervisionMovilDetalleSCOP.class.getSimpleName(), json);
        memoryList = supervisionMovilDetalleSCOPList;
    }

    @Override
    public void deleteSupervisionMovilDetalleSCOPListFromLocal(Context context) {
        PuntoControlUtils.deleteExternalFile(context, SupervisionMovilDetalleSCOP.class.getSimpleName());
        memoryList = null;
    }

    public static SupervisionMovilDetalleScopDAOImpl getInstance(){
        if(instance == null){
            instance = new SupervisionMovilDetalleScopDAOImpl();
        }
        return instance;
    }
}
